package org.slicerj.core;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ProcessExecuter {
	Process pr = null;
	String cmd;

	public ProcessExecuter(String cmd) {
		this.cmd = cmd;
	}

	public void execute() {
		Runtime run = Runtime.getRuntime();
		System.out.println(cmd);
		try {
			pr = run.exec(cmd);
			pr.waitFor();
		} catch (IOException e) {
			// TODO: handle exception
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		BufferedReader buf = new BufferedReader(new InputStreamReader(
				pr.getInputStream()));

		String line;
		try {
			line = buf.readLine();
			while (line != null) {
				System.out.println(line);
				line = buf.readLine();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
